package Demo01.Books;

class Book implements Comparable<Object>{
	int id;
	String name;
	String author;
	int price;
	int sale;
	public Book() {
		super();

	}
	public Book(int id, String name, String author, int price, int sale) {
		super();
		this.id = id;
		this.name = name;
		this.author = author;
		this.price = price;
		this.sale = sale;
	}
	@Override
	public int hashCode() {
		
		return name.hashCode()+id*1000;
	}
	@Override
	public boolean equals(Object obj) {
		Book book=(Book)obj;
		return this.name.equals(book.name)&&this.id==book.id&&this.author.equals(book.author);
	}
	@Override
	public int compareTo(Object o) {
		Book book=(Book)o;
		//先比较书名
		int num = book.name.compareTo(this.name);
		if (num==0) {
			return this.id-book.id;
		}
		else{
			return num;
		}
	}
	@Override
	public String toString() {
		return "Book [id=" + id + ", name=" + name + ", author=" + author + ", price=" + price + ", sale=" + sale + "]";
	}
	
}
